#pragma once
#include "entity.h"
#include "render/rendermesh.h"

struct particlevertex_t
{
	float4 posrot;
	float4 sizealpha;
//	coloru8 color;
//	uint16 uv[2];
	float4 color;
	float uv[2];
};

struct particlenode_t
{
	float3 pos;
	float3 vel;
	float rot;
	float rotvel;
	float size;
	float sizevel;
	float time;
	float4 color;
};

struct particlesystem_t;
struct shader_t;
struct particle_renderobject:renderobject_t
{
	particle_renderobject(particlesystem_t* _ps):ps(_ps){}

	particlesystem_t* ps;
	void onrender();
	void setupbuffers();
};
struct particlesystem_t:entity_t
{
	DECLARE_ENTITY;

	particlesystem_t();
	void onload();
	void init();
	void update();
	void render();
	void exit();
	void onrender();
	void setupbuffers();
	void spawn();
	void start();
	void stop();

#ifdef LEO_DESIGNER
	void onchangeproperty(const stringhash& propname);
#endif

	particle_renderobject ro;

	vertexbuffer_t vb;
	rendermaterial_t* mat;
//	shader_t* sh;
	rendertexture_t* tex;

	bool started;
	float spawn_frac;
	int lifetime_counter;

	vector<particlenode_t> particlebuf;


	//props
	stringhash texture_name;
	int particlenum_max;
	float	spawn_freq;
	int		emitter_lifespan;
	float3	emitterbox_size;

	float	particle_size_min;
	float	particle_size_max;
	float	particle_size_velocity;
	float	particle_size_damping;

	float	rotation_default_min;
	float	rotation_default_max;
	float	rotation_speed_min;
	float	rotation_speed_max;
	float	rotation_speed_damping;

	float	velocity_min;
	float	velocity_max;
	float	velocity_damping;

	float	gravity;

	float	spawn_angle;

	float4	global_color;
	float4	color_random_min;
	float4	color_random_max;

	float	fadein_time;
	float	fadeout_time;
	float	maradjonugy_time;
	stringhash material;

	bool	autostart;

};

inl   void particle_renderobject::onrender()
{
	ps->onrender();
}

inl   void particle_renderobject::setupbuffers()
{
	ps->setupbuffers();
}


struct light_t:entity_t
{
	DECLARE_ENTITY;
	light_t();
	void update();
#ifdef LEO_DESIGNER
	void render();
#endif

	//props
	float radius;
	float4 color;
	float strength;
};